<template>
    <div>
        <StElDynamicForm
                ref="form"
                :options="formItems"
                :helper-form="{msgType: 'video'}"
                @requestSuccess="submitSuccess"
                :submit-props="{method: 'post',url: uploadVideoUrl(),label: '获取可群发的素材id'}"
                :origin-prop="{inline: true,labelWidth: '100px'}"
        >
        </StElDynamicForm>
        <MassDoSend :form-data="formData"></MassDoSend>
    </div>

</template>

<script>
    import MassDoSend from './MassDoSend.vue'
    import MpUrl from '../MpUrl.js'
    export default {
        components:{
            MassDoSend
        },
        data(){
            return {

            submitSuccessData: null,
                formItems:[
                    {
                        field: {
                            name: 'appCode'
                        },
                        element:{
                            type: 'select',
                            required: true,
                            options:{
                                datas: MpUrl.configList,
                                optionProp:{
                                    value: 'appCode',
                                    label: 'appName'
                                }
                            },
                            label: '公众号',
                        }
                    },
                    {
                        field: {
                            name: 'title'
                        },
                        element:{
                            label: '标题',
                            options: {
                                placeholder: '视频的标题',
                            },
                            required: true,
                        }
                    },
                    {
                        field: {
                            name: 'description'
                        },
                        element:{
                            label: '描述',
                            options: {
                                placeholder: '视频的描述',
                            },
                            required: true,
                        }
                    },
                    {
                        field: {
                            name: 'mediaId'
                        },
                        element:{
                            label: '媒体id',
                            options: {
                                placeholder: '需要在素材管理中获取,永久素材媒体id',
                            },
                            tips: '需要在素材管理中获取,永久素材媒体id',
                            required: true,
                        }
                    },

                ],
            }
        },
        methods:{
            submitSuccess(data, form) {
                this.submitSuccessData = data
            },
            uploadVideoUrl(){
                if(!this.$refs.form){
                    return null
                }
                let appCode = this.$refs.form.getFormData().appCode

                return  this.$stStringTools.replaceb(MpUrl.MassHairVideoAdd,{appCode: appCode})
            },
            formData(){
                let r = false
                this.$refs.form.getFormRef().validate((valid)=>{
                    if(valid){
                        r = true
                    }
                })
                if(r == false){
                    this.$message.error('请先获取可群发的素材id')
                    return false
                }
                if (!this.submitSuccessData) {
                    this.$message.error('请先获取可群发的素材id')
                    return false
                }
                let formData =  this.$refs.form.getFormData()
                formData.mediaId = this.submitSuccessData.mediaId
                return formData
            }
        }
    }
</script>

<style scoped>

</style>